﻿/*
 * @file: RolesBLL.cs
 * @in namespace: BLL
 */
using System;
using System.Data;
using DAL;

namespace BLL
{
    public class RolesBLL
    {
        public RolesBLL()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        #region IRoles Members

        /// <summary>
        /// GetRoles
        /// </summary>
        /// <param name="allowFilter">"true" if allow ignore hidden records</param>
        /// <returns>Records corresponding</returns>
        public static Roles[] GetRoles(bool allowFilter)
        {
            try
            {
                return DataAccessHelper.GetRolesDA().GetRoles(allowFilter);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// GetRoleByRoleID
        /// </summary>
        /// <param name="roleID">Role ID</param>
        /// <param name="allowFilter">"true" if allow ignore hidden records</param>
        /// <returns>Record corresponding</returns>
        public static Roles GetRoleByRoleID(int roleID, bool allowFilter)
        {
            try
            {
                return DataAccessHelper.GetRolesDA().GetRoleByRoleID(roleID, allowFilter);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// InsertRole
        /// </summary>
        /// <param name="role">Role entity</param>
        /// <param name="autoNumber">Current Role ID inserted(output)</param>
        /// <returns>1 if successful, 0 if error occurred</returns>
        public static int InsertRole(Roles role, out int autoNumber)
        {
            try
            {
                if (role.RoleName == null || role.RoleName.Length == 0)
                    throw new OnlineFloralDeliveryException(2, "RoleName is not allow null of empty");
                else if (RolesDA.RoleNameExisted(role.RoleName) > 0)
                    throw new OnlineFloralDeliveryException(1, "RoleName existed");
                return DataAccessHelper.GetRolesDA().InsertRole(role, out autoNumber);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// UpdateRole
        /// </summary>
        /// <param name="role">Role entity</param>
        /// <returns>1 if successful, 0 if error occurred</returns>
        public static int UpdateRole(Roles role)
        {
            try
            {
                if (role.RoleID == 0)
                    throw new OnlineFloralDeliveryException(2, "RoleID is not allow null or empty");
                else if (role.RoleName == null || role.RoleName.Length == 0)
                    throw new OnlineFloralDeliveryException(2, "RoleName is not allow null of empty");
                return DataAccessHelper.GetRolesDA().UpdateRole(role);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// DisableRole
        /// </summary>
        /// <param name="roleID">Role ID</param>
        /// <param name="isEnable">"true" if allow enable Role, "false" if allow hidden Role</param>
        /// <returns></returns>
        public static int DisableRole(int roleID, bool isEnable)
        {
            try
            {
                return DataAccessHelper.GetRolesDA().DisableRole(roleID, isEnable);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion
    }
}
